/* msg.c : messaging system (assignment 2)
 */

#include <kernel.h>

/*
*	Function to complete a send operation
*/
extern int send(void* send_buf, int send_len, void* recv_buf, int recv_len){
	if(!basicchecks(send_buf, send_len, recv_buf, recv_len)) return -2;
	
	if(send_len < recv_len) recv_len = send_len;

	blkcopy(recv_buf, send_buf, recv_len);
	return recv_len;
}
/*
*	Function to complete a receive operation
*/
extern int recv(void* send_buf, int send_len, void* recv_buf, int recv_len){
	if(!basicchecks(send_buf, send_len, recv_buf, recv_len)) return -2;
	
	if(send_len < recv_len) recv_len = send_len;

	blkcopy(recv_buf, send_buf, recv_len);
	return recv_len;
}
/*
*	Helper function for basic input checking
*/
int basicchecks(void* send_buf, int send_len, void* recv_buf, int recv_len){
	if((int)send_buf<0) return 0;
	if((int)recv_buf<0) return 0;
	if(send_len<0) return 0;
	if(recv_len<0) return 0;
	return 1;
}
